<template>
    <view class="box">
        <view class="amount">￥{{ orderMoney }}</view>
        <view class="account">
            <view>订单编号</view>
            <view>{{ orderId }}</view>
        </view>
        <view class="pay">
            <view>
                <image class="img" src="../../../static/weixin.png"></image>
            </view>
            微信支付
        </view>
        <view class="confirm buttonTopUp" @click="pay">确认支付</view>
    </view>
</template>
<script>
    export default {
        data() {
            return {
                orderId: "",
                orderMoney: "",
            };
        },
        onLoad(option) {
            this.orderMoney = option.orderMoney;
            this.orderId = option.orderId;
            console.log(23, option);
        },
        methods: {
            pay() {
                let data = {
                    payWay: 0,
                    userId: this.$store.state.userInfo.userId,
                    orderId: this.orderId,
                    paymentUserId: this.$store.state.userInfo.openId,
                };

                this.$request(this.$api.payForPayScore, data, "POST").then((res) => {
                    console.log("请求回来的数据");
                    if (res.code === 200) {
                        uni.requestPayment({
                            nonceStr: res.result.nonceStr,
                            package: res.result.package,
                            signType: res.result.signType,
                            paySign: res.result.paySign,
                            timeStamp: res.result.timeStamp,
                            success(res) {
                                console.log(225, res);
                                uni.showToast({
                                    title: "支付成功!",
                                });
                                uni.navigateTo({
                                    url: "results_pay",
                                });
                            },
                        });
                    } else if (res.code === 600) {
                        console.log("返回", res.code);
                        console.log("返回1", res.message);
                        uni.showToast({
                            title: res.message,
                            icon: "error",
                        });
                        setTimeout(function() {
                            uni.navigateTo({
                                url: "/pages/mine/order/newOrder",
                            });
                        }, 2000);
                    }
                });
            },
        },
    };
</script>
<style>
    .box {
        margin: 50rpx;
        position: relative;
    }

    .amount {
        display: flex;
        justify-content: center;
        font-size: 70rpx;
        font-weight: 700;
    }

    .balance {
        margin: 20rpx 0 0 0;
        display: flex;
        justify-content: center;
        font-size: 30rpx;
        color: #a6a4a4;
    }

    .account {
        padding: 25rpx;
        display: flex;
        margin: 30rpx 50rpx;
        justify-content: space-between;
        font-size: 30rpx;
    }

    .pay {
        background-color: #fff;
        border: 1px solid #bcbaba;
        width: 100%;
        height: 130rpx;
        display: flex;
        justify-content: start;
        align-items: center;
    }

    .img {
        width: 60px;
        height: 50px;
        margin: 5px 5px 0 10px;
    }

    .buttonTopUp {
        background-color: #fbeb60;
        font-size: 32rpx;
        height: 50px;
        width: 185px;
        bottom: -120%;
        left: 22%;
        position: absolute;
        display: flex;
        justify-content: center;
        align-items: center;
        border-radius: 8rpx;
    }
</style>